package Application.Controller;

import Application.AppJoint;
import javafx.fxml.FXML;
import javafx.scene.control.Slider;
import javafx.scene.control.TextArea;
import javafx.scene.control.TextField;
import javafx.stage.Stage;

public class NewCanvasController extends Controller{

    @FXML
    TextField widthText;
    @FXML
    TextField heightText;

    @FXML
    Slider widthSlider;

    @FXML
    Slider heightSlider;

//    @FXML public void shutDownOnAction(){
//        getLocalStage().close();
//        getPrimarStage().close();
//    }
//
//    @FXML public void cancleOnAction(){
//        getLocalStage().close();
//    }

    @FXML public void comfirmedOnAction(){

        String widthTextStr= widthText.getText();
        String heightTextStr = heightText.getText();

        if(widthTextStr.equals("")){
            return;
        }

        if(heightTextStr.equals("")){
            return;
        }

        int width = Integer.parseInt(widthText.getText());
        int height = Integer.parseInt(heightText.getText());

        if(width == 0){
            return;
        }

        if(height == 0){
            return;
        }

        this.getMain().showMainWindow();

        AppJoint.getInstance().setCanvasWidth(width);
        AppJoint.getInstance().setCanvasHeight(height);

        MainWindowController mainWindowController = AppJoint.getInstance().getMainWindowController();

        mainWindowController.getViewport().setFitWidth(AppJoint.getInstance().getCanvasWidth());
        mainWindowController.getViewport().setFitHeight(AppJoint.getInstance().getCanvasHeight());

        AppJoint.getInstance().createOutImage();
        AppJoint.getInstance().bondImg();
        getLocalStage().close();
    }

    @FXML public void widthSliderDrag(){
        int num = (int)widthSlider.getValue();
        num*=5;

        widthText.setText(String.valueOf(num));
    }

    @FXML public void heightSliderDrag(){
        int num = (int)heightSlider.getValue();
        num*=5;

        heightText.setText(String.valueOf(num));
    }

    @FXML public void textWidthOnAction(){
        if(widthText.getText().equals("")){
            return;
        }

        int num = Integer.parseInt(widthText.getText());
        if(num>=500){
            num = 500;
        }
        num/=5;
        System.out.print(num);
        widthSlider.setValue(num);
    }

    @FXML public void textHeightOnAction(){
        if(heightText.getText().equals("")){
            return;
        }
        int num = Integer.parseInt(heightText.getText());
        if(num>=500){
            num = 500;
        }
        num/=5;
        System.out.print(num);
        heightSlider.setValue(num);
    }
}
